package com.linedata.acq.metier.norme.fmb;

import oracle.forms.jdapi.Canvas;
import oracle.forms.jdapi.FormModule;
import oracle.forms.jdapi.JdapiIterator;

public class GCAN_FMB {

	private FormModule	fmb;

	public GCAN_FMB(FormModule fmb) {
		this.fmb = fmb;
	}

	private String	error	= "";

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error += error;
	}

	/**
	 * EKFR001_1:: Le nom du canevas est PAGE_n
	 * 
	 * @param fmb
	 */
	public void nomCanvas() {

		// FIXME NullPointerException: SubClassParent introuvable
		for (JdapiIterator canvases = fmb.getCanvases(); canvases.hasNext();) {

			Canvas canvas = (Canvas) canvases.next();
			if (canvas.getSubclassParent().getName().equals("IESO$CANVAS") && !canvas.getName().startsWith("PAGE_"))
				this.setError("\tEKFR001_1 : " + canvas.getName() + "\n");
		}
	}

	/**
	 * EKFR002_1 :: Le nom des canevas footer de retour est FOOTER_nom_canevas
	 * 
	 * @param fmb
	 */
	public void nomFooterCanvas() {

		for (JdapiIterator canvases = fmb.getCanvases(); canvases.hasNext();) {

			Canvas canvas = (Canvas) canvases.next();
			if (canvas.getSubclassParent().getName().equals("IESO$FOOTER_PAGE")
					&& !canvas.getName().equals("FOOTER_" + canvas.getWindowName()))
				this.setError("\tEKFR001_1 : " + canvas.getName() + "\n");
		}
	}

	/**
	 * EKFR003_1 :: Le nom et les proipriétés des canevas PAGE_1 et
	 * FOOTER_PAGE_1 ne sont pas modifiés
	 * 
	 * @param fmb
	 */
	public void nomPropCanvas() {

		boolean trouveP = false;
		boolean trouveF = false;

		for (JdapiIterator canvases = fmb.getCanvases(); canvases.hasNext();) {
			Canvas canvas = (Canvas) canvases.next();
			if (canvas.getName().equals("PAGE_1")) {
				// TODO Property not changed
				trouveP = true;
			}
			if (canvas.getName().equals("FOOTER_PAGE_1")) {
				// TODO Property not changed
				trouveF = true;
			}
		}

		if (!trouveP) {
			this.setError("\tEKFR003_1 : PAGE_1 does not exists\n");
		}
		if (!trouveF) {
			this.setError("\tEKFR003_1 : FOOTER_PAGE_1 does not exists\n");
		}
	}

	/**
	 * EKFR052_1 :: Le propriété Bevel de l'onglet est positionné à No
	 * 
	 * @param fmb
	 */
	public void propBevel() {

	}

	@Override
	public String toString() {
		return this.getError();
	}

}
